package com.logic.modular.game.battle.process.skillEffectHandle.impl;

import com.logic.modular.game.battle.panel.attribute.PlayerHeroAttributeServiceImpl;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffectServiceImpl;
import com.logic.modular.game.battle.panel.skillEffect.domain.SkillEffectLayer;
import com.logic.modular.game.battle.process.domain.Reason;
import com.logic.modular.game.battle.process.skillEffectHandle.base.BaseSkillEffectStrategy;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class AttributeStrategy extends BaseSkillEffectStrategy {
    @Resource
    private PvpSkillEffectServiceImpl skillEffectService;
    @Resource
    private PlayerHeroAttributeServiceImpl attributeService;

    @Override
    public PvpSkillEffect applyEffect(PvpSkillEffect pvpSkillEffect) {
        effectHandle1.tryInitProperties(pvpSkillEffect);
        effectHandle2.tryTriggerJudgment(pvpSkillEffect);
        effectHandle2.logTriggerFailReasons(pvpSkillEffect);

        apply(pvpSkillEffect);
        return pvpSkillEffect;
    }

    @Override
    public PvpSkillEffect apply(PvpSkillEffect pvpSkillEffect) {
        Integer status = pvpSkillEffect.status.getStatus();
        if (pvpSkillEffect.status.getIsTrigger() != 1) {
            Reason reason = new Reason();
            reason.setSuccess(false);
            reason.setType(status);
            reason.setReasonSource(null);
            pvpSkillEffect.skillEffectTriggerInfo.setReason(reason);
            pvpSkillEffect.skillEffectTriggerInfo.setSkillEffectLayer(new ArrayList<>());
            attributeService.refreshPanel(pvpSkillEffect);
            return pvpSkillEffect;
        }
        effectHandle4.tryHandleLayerValue(pvpSkillEffect);
        effectHandle5.tryCoverHandle(pvpSkillEffect);

        SkillEffectLayer skillEffectLayer = pvpSkillEffect.getSkillEffectLayer();
        attributeService.refreshPanel(pvpSkillEffect);

        List<SkillEffectLayer> list = new ArrayList<>();
        list.add(skillEffectLayer);
        pvpSkillEffect.skillEffectTriggerInfo.setSkillEffectLayer(list);

        Reason reason = new Reason();
        reason.setSuccess(true);
        reason.setType(status);
        reason.setReasonSource(null);
        pvpSkillEffect.skillEffectTriggerInfo.setReason(reason);
        return pvpSkillEffect;
    }
}
